﻿using Childhood.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using AttributeRouting.Web.Mvc;

namespace Childhood.Controllers
{
    public partial class AboutController : Controller
    {
        //
        // GET: /About/
        childhoodDiariesEntities _entity = new childhoodDiariesEntities();

        [GET("thong-tin/{footerCategory?}")]
        public virtual ActionResult Index(string footerCategory, int? page)
        {
            try
            {
                if (null == footerCategory)
                {
                    return RedirectToAction("Index", "Error", new { statusCode = 404, lastError = new NullReferenceException(), isAjaxRequet = false });
                }else{
                    var lstCategory = _entity.tbFooterCategory.Where(c => c.C_url.Trim().ToLower() == footerCategory.Trim().ToLower()).FirstOrDefault();
                    var lstNews = _entity.tblFooter.Where(n => n.C_type == lstCategory.C_id).ToList();
                    var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1)
                    var onePageOfNews = lstNews.ToPagedList(pageNumber, 10); // will only contain 10 products max because of the pageSize;
                    ViewBag.Category = lstCategory;
                    ViewBag.onePageOfNews = onePageOfNews;
                    return View();
                }
            }
            catch (Exception ex)
            {
                return RedirectToAction("Index", "Error", new { statusCode = 404, lastError = ex, isAjaxRequet=false });
            }
        }

    }
}
